<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>添加商品</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片内容区域 -->
    <el-card>
      <!-- 第一行 搜索框gutter 设置 单元格间隔 -->
      <el-row :gutter="20">
        <!-- 第1列 span 设置列的 宽度比例（每行的总span为24） -->
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            ref="searchInput"
            clearable
            v-model="queryData.query"
            @clear="getOrderList"
          >
            <el-button
              @click="search"
              slot="append"
              icon="el-icon-search"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="orderList" border style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="350">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="">
        </el-table-column>
        <el-table-column label="是否付款" width="">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status == '0'"
              >未付款</el-tag
            >
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.add_time | dateFormat }}
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="isEditAdressShow = true"
            ></el-button>
            <!-- 显示物流对话框 按钮 -->
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="showProgressDialog"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        :current-page="queryData.pagenum"
        @current-change="pageChange"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="queryData.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="提示" :visible.sync="isEditAdressShow" width="50%">
      <!-- 级联 -->
      <el-cascader
        v-model="selectedCityIds"
        :options="cityList"
        :props="{ expandTrigger: 'hover' }"
      ></el-cascader>
      <!-- 按钮区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="isEditAdressShow = false">取 消</el-button>
        <el-button type="primary">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="isProgressDialogShow"
      width="50%"
    >
      <!-- 物流进度 -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in wuliuProgress"
          :key="index"
          :timestamp="activity.ftime"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityList from './citydata.js'
export default {
  data() {
    return {
      //分页请求参数对象
      queryData: {
        query: '', //查询关键字
        pagenum: 1, //当前页码
        pagesize: 5, //页容量（每页显示的行数）
      },
      //商品列表数组
      orderList: [],
      //总商品数量
      total: 0,
      isEditAdressShow: false, //修改地址对话框 开关
      selectedCityIds: [], //选中的要修改的城市id
      cityList, //直接获取导入的城市数组
      isProgressDialogShow: false, //屋里进度对话框 开关
      wuliuProgress: [],
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    //请求并渲染订单列表
    async getOrderList() {
      //a.请求分页数据
      const { data: resData } = await this.$http.get('orders', {
        params: this.queryData,
      })
      console.log(resData)

      //b.如果请求失败
      if (resData.meta.status != 200)
        return this.$message.error(resData.meta.msg)
      //c.如果请求成功 将数组 设置给 data.goodList 数组 用于视图表格渲染
      this.orderList = resData.data.goods
      this.total = resData.data.total
    },
    //2.页容量 改变事件
    handleSizeChange(newSize) {
      //a.修改查询参数对象 的 页容量
      this.queryData.pagesize = newSize

      //b.重新请求商品列表
      this.getOrderList()
    },
    //3.页码改变事件
    pageChange(newPage) {
      //a.修改查询参数对象 的 当前页码
      this.queryData.pagenum = newPage
      //b.重新请求商品列表
      this.getOrderList()
    },
    //搜索
    search() {
      //b.重新请求商品列表
      this.getOrderList()
    },
    //
    async showProgressDialog() {
      //显示 物流对话框
      this.isProgressDialogShow = true
      //请求物流数据
      let { data: resData } = await this.$http.get('/kuaidi/1106975712662')
      //   console.log('物流', resData)
      // 如果失败
      if (resData.meta.status !== 200) this.$message.error(resData.meta.msg)
      // 如果成功
      // 挂载数据到data中,供视图使用
      this.wuliuProgress = resData.data
      // 显示 物流对话框
      this.isProgressDialogShow = true
    },
  },
}
</script>

<style lang="less" scoped>
</style>